// 手写foreach函数
Array.prototype.myForeach = function (callback, thisArg) {
  if(typeof callback !== "function") {
    throw new TypeError(callback + "mast to be a function");
  }
  if (!Array.isArray(this)) {
    throw new TypeError("this mast to be a Array");
  }
  let len = this.length;

  for(let i=0;i<len;i++){
    callback.call(thisArg, this[i], i, this);
  }
}

const testArray = [1,2,3,4,5,6];
testArray.myForeach((item, index) => {
  console.log(item, index);
})